<!-- company表单弹窗 -->
<form id="titleType-form" lay-filter="titleType-form" class="layui-form model-form">
    <input id="tttpid" name="tttpid" type="hidden"/>
    <div class="layui-form-item">
        <label class="layui-form-label">称号类型名称</label>
        <div class="layui-input-block">
            <input id="tpname" name="tpname" placeholder="请输入称号类型名称" type="text" class="layui-input" maxlength="20"
                   lay-verify="required" required/>
        </div>
    </div>
	<div class="layui-form-item">
	    <label class="layui-form-label">称号类型CODE</label>
	    <div class="layui-input-block">
	        <input id="tpCode" name="tpCode" placeholder="请输入称号类型CODE" type="text" class="layui-input" maxlength="20"
	               lay-verify="required" required/>
	    </div>
	</div>
    <div class="layui-form-item model-form-footer">
        <button class="layui-btn layui-btn-primary" ew-event="closeDialog" type="button">取消</button>
        <button class="layui-btn" lay-filter="titleType-form-submit" lay-submit>保存</button>
    </div>
</form>

<script>
    layui.use(['layer', 'admin', 'form'], function () {

        var layer = layui.layer;
        var admin = layui.admin;
        var form = layui.form;

        form.render();
        // debugger;
        // 回显titleType数据
        var titleType = admin.getTempData('titleType');
        if (titleType) {
            form.val('titleType-form', titleType);
        }
        // 表单提交事件
        form.on('submit(titleType-form-submit)', function (data) {
            layer.load(2);
            // debugger;
            if (data.field.tttpid != null && data.field.tttpid != ''){
                admin.req('api-user/titleType/updateTitleType', JSON.stringify(data.field), function (data) {
                    layer.closeAll('loading');
                    if (data.code == 0) {
                        layer.msg(data.msg, {icon: 1, time: 2000});
                        admin.finishPopupCenter();
                    } else {
                        layer.msg(data.msg, {icon: 2, time: 2000});
                    }
                }, 'POST');
                return false;
            } else {
                admin.req('api-user/titleType/addTitleType', JSON.stringify(data.field), function (data) {
                    layer.closeAll('loading');
                    if (data.code == 0) {
                        layer.msg(data.msg, {icon: 1, time: 2000});
                        admin.finishPopupCenter();
                    } else {
                        layer.msg(data.msg, {icon: 2, time: 2000});
                    }
                    }, 'POST');
                return false;
            }
        });


    });
</script>